<template>
  <view class="container">
    <!-- 面试题列表 -->
    <view class="questions-section">
      <view class="question-list">
        <view
            class="question-item"
            v-for="(item, index) in favoriteQuestions"
            :key="index"
            @click="viewQuestionDetail(item)"
        >
          <view class="question-main">
            <view class="question-header">
              <view class="question-number">{{ index + 1 }}</view>
              <view class="question-title">{{ item.content || '暂无标题' }}</view>
            </view>
          </view>
          <view class="question-meta">
            <difficulty-tag :difficulty="item.difficulty || '中等'" />
          </view>
        </view>

        <!-- 无收藏时显示 -->
        <view v-if="favoriteQuestions.length === 0" class="no-favorites">
          <image :src="'https://youke1.picui.cn/s1/2025/09/18/68cbfee87ade0.png'" class="empty-icon"></image>
          <view class="empty-text">暂无数据</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import DifficultyTag from '@/components/difficulty-tag.vue';
import config from '@/common/config.js';

export default {
  components: {
    DifficultyTag
  },
  data() {
    return {
      favoriteQuestions: [], // 收藏的面试题列表
    };
  },

  onLoad(options) {
    // 页面加载时获取收藏列表
    this.getFavoriteQuestions();
  },

  methods: {
    // 获取收藏的面试题列表
    getFavoriteQuestions() {
      this.$request('/interview/favorite/listFavoriteQuestion', 'GET')
          .then(res => {
            if (res.code === 200) {
              this.favoriteQuestions = res.rows || [];
            } else {
              console.error('获取收藏列表失败:', res);
              this.favoriteQuestions = [];
              uni.showToast({
                title: '获取收藏列表失败',
                icon: 'none'
              });
            }
          }).catch(err => {
        console.error('获取收藏列表异常:', err);
        this.favoriteQuestions = [];
        uni.showToast({
          title: '获取收藏列表异常',
          icon: 'none'
        });
      });
    },

    viewQuestionDetail(item) {
      // 跳转到详情页
      uni.navigateTo({
        url: `/pages/favorite/detail?questionId=${encodeURIComponent(item.questionId)}&categoryId=${item.categoryId}`
      });
    }
  }
}
</script>

<style>
.empty-icon {
  height: 200rpx;
  width: 245rpx;
  margin: 100rpx auto;
  display: block;
}

.empty-text {
  text-align: center;
  color: #999;
  font-size: 28rpx;
}

.no-favorites {
  padding: 50rpx 0;
}

.no-favorites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IgZmlsbC1vcGFjaXR5PSIxIi8+PC9nPjxnIHRyYW5zZm9ybT0ibWF0cml4KDEsMCwwLC0xLDAsMTc4MikiPjxlbGxpcHNlIGN4PSIxODUiIGN5PSI5MDgiIHJ4PSIxNyIgcnk9IjE3IiBmaWxsPSJ1cmwoI21hc3Rlcl9zdmczXzlfMDMzKSIgZmlsbC1vcGFjaXR5PSIxIi8+PC9nPjxnIHRyYW5zZm9ybT0ibWF0cml4KDEsMCwwLC0xLDAsMTU0NikiPjxlbGxpcHNlIGN4PSIxMDMzIiBjeT0iNzkwIiByeD0iMTciIHJ5PSIxNyIgZmlsbD0idXJsKCNtYXN0ZXJfc3ZnNF85XzAzMykiIGZpbGwtb3BhY2l0eT0iMSIvPjwvZz48ZyB0cmFuc2Zvcm09Im1hdHJpeCgxLDAsMCwtMSwwLDEyOTApIj48ZWxsaXBzZSBjeD0iODgzLjUiIGN5PSI2NzkuNSIgcng9IjM0LjUiIHJ5PSIzNC41IiBmaWxsPSJ1cmwoI21hc3Rlcl9zdmc1XzlfMDMzKSIgZmlsbC1vcGFjaXR5PSIxIi8+PC9nPjwvZz48L3N2Zz4=");
  background-position-y: -260rpx;
  background-size: contain;
  background-repeat: no-repeat;
  background-color: #ffffff;
}

.questions-section {
  padding: 0 15px;
}
.question-list {
  padding-top: 20px;
  background: transparent;
  border-radius: 20px;
}

.question-item {
  padding: 15px;
  border-bottom: var(--primary-light-color);
  transition: all 0.3s;
  display: flex;
  justify-content: space-between;
}

.question-item:last-child {
  border-bottom: none;
}

.question-item:hover {
  background: #f9f9f9;
  border-radius: 10px;
}

.question-main {
  margin-bottom: 10px;
  width: 75%;
}

.question-header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.question-number {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: var(--primary-light-color);
  color: var(--primary-dark-color);
  font-size: 14px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
  flex-shrink: 0;
}

.question-title {
  font-size: 16px;
  font-weight: bold;
  color: #333;
  flex: 1;
}

.question-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #999;
  margin-left: 10px;
}
</style>